<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    <div id="app">
        {{ msg }}
        <child v-bind:parent-data="newMsg">
        </child>
    </div>

    <script src="./js/vue.js"></script>
    <script>
        // 父子组件传参

        Vue.component('child', {
            props: ['parentData'],
            // 全局污染
            data() {
                return {
                    msg: 'this is my component msg'
                }
            },
            methods: {
                add() {
                    console.log(this.msg)
                    // this.msg = 'test'
                }
            },
            template: `<div>
                        {{ msg }}
                        <div>这是从父组件接收到的数据：{{ parentData }}</div>
                        <button v-on:click="add">click</button>
                        这是header组件
                    </div>`
        })

        var myApp = new Vue({
            el: '#app',
            data: {
                msg: 'this is my message',
                newMsg: '这是我重新定义的数据(父组件)'
            },
            methods: {

            }
        })
    </script>
</body>

</html>